home *** CD-ROM | disk | FTP | other *** search
- Path: mdw084.cc.monash.edu.au!pdrod1
- From: pdrod1@mdw084.cc.monash.edu.au (Mr Paul Rodger)
- Newsgroups: comp.lang.c
- Subject: passing 2D arrays to functions
- Date: 18 Apr 1996 11:26:12 GMT
- Organization: Monash University
- Message-ID: <4l58sk$l6r@harbinger.cc.monash.edu.au>
- NNTP-Posting-Host: mdw084.cc.monash.edu.au
- X-NNTP-Posting-User: pdrod1
- X-Newsreader: NN version 6.5.0 CURRENT #12
-
- Greets -
-
- I need to pass a 2-dimensional array to a function. Obviously I just want
- to pass a pointer to the first element, and in the past when I wanted to
- pass a one-dimensional array to a function I did the following which should
- work fine:
-
- fun(int array[])
- {
- ...
- }
-
- main()
- {
- int array[10];
- ...
- fun(array);
- }
-
- But when I try to pass a 2D array using the same method, slightly different:
-
- fun(int array[][])
- {
- ...
- }
-
- main()
- {
- int array[10][10];
- ...
- fun(array);
- }
-
- I'm getting errors:
-
- main.c:221: arithmetic on pointer to an incomplete type
- make: *** [main.o] Error 1
-
- This occurs when I try to look at elements in the array when I am
- in the 'fun' function:
-
- array[1][1] = 1;
-
- Would this be because of vagueness about row-major or column-major form?
- I've got around this in the past by putting the 2D array in a struct,
- and passing a pointer to a struct, but in this case I can't do that
- because the array size could vary as it is declared various times in
- iterations. (It isn't declared in main like above - this is just a
- simplication).
-
- I'm using gcc 2.7.0 for linux, but had this problem before with BCPP.
-
- Any help would be great.. :)
- --
- ._____________________________________________________________________.
- | "We all get a little crazy sometimes" - Norman Bates |
- \_____________________________________________________________________/
-
-